/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : join_room_creat01.js                                 
*  Description  : 조인룸 생성
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-06-13  김효순    Created.  
*******************************************************************************/

jQuery(function($){
	// 진행상황
	function clsProgressStatus()
	{
		this._HTMLDom = null;
		this._listData = null;
		this._ERRMSG = {
			"_NOVALUE": "진행상황을 선택해 주십시요."
		}
		this.errMsg = null;
		
		this._init();
	}
	
	clsProgressStatus.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(0)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:radio").attr("name", "rdoProgressStatus");
			
			this._listData = ["C", "E"];
			this.setValue("C");
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, getError: function(){
			if(this.errMsg) return this._ERRMSG[this.errMsg];
			else return null;
		}
		, valid: function(){
			var $layer = this.$getLayer();
			
			if($layer.find("input:radio:checked").length == 0){
				this.errMsg = "_NOVALUE";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this.$getLayer().find("input:radio:first").trigger("focus");
		}
		, getValue: function(){
			var $layer = this.$getLayer();
			
			var n = $layer.find("input:radio").index($layer.find("input:radio:checked"));
			
			if(n >= 0) return this._listData[n];
			else return null;
		}
		, setValue: function(val){
			var $layer = this.$getLayer();
			
			var n = $.inArray(val, this._listData);
			
			$layer.find("input:radio:eq(" + n + ")").trigger("click");
			setTimeout(function(){
				$layer.find("input:radio:checked").trigger("click");
			}, 500);
		}
	}
	
	// 공개여부
	function clsOpenYN()
	{
		this._HTMLDom = null;
		this._listData = null;
		this._ERRMSG = {
			"_NOVALUE": "공개여부를 선택해 주십시요."
			, "_INVALID": "비밀번호는 4자리 숫자만 가능합니다."
		}
		this.$errObj = null;
		this.errMsg = null;
		
		this._init();
	}
	
	clsOpenYN.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(1)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:radio").attr("name", "rdoOpenYN");
			
			var $text = $layer.find("input:text");
			
			$text.after("<input type='password'").next("input:password").attr({
				"class": $text.attr("class")
				, "maxLength": $text.attr("maxLength")
			});
			$text.remove();
			
			this._listData = ["Y", "N"];
			
			this.setPasswdState();
			
			this.setValue("Y");
		}
		, $getLayer: clsProgressStatus.prototype.$getLayer
		, getError: clsProgressStatus.prototype.getError
		, valid: function(){
			var $layer = this._HTMLDom["$layer"];
			var reg = /^[0-9]{4}$/ig;
			var passwd = $layer.find("input:password").val();
			
			if($layer.find("input:radio:checked").length == 0){
				this.errMsg = "_NOVALUE";
				this.$errObj = $layer.find("input:radio:first");
				return false;
			}else if($layer.find("input:radio:eq(1)").is(":checked") && !reg.test(passwd)){
				this.errMsg = "_INVALID";
				this.$errObj = $layer.find("input:password");
				return false;
			}
			
			return true;
		}
		, focus: function(){
			if(this.$errObj) this.$errObj.trigger("focus");
			else $layer.find("input:radio:first").trigger("focus");
		}
		, getValue: clsProgressStatus.prototype.getValue
		, setValue: clsProgressStatus.prototype.setValue
		, getPasswordValue: function(){
			return this.$getLayer().find("input:password").val();
		}
		, setPasswordValue: function(val){
			this.$getLayer().find("input:password").val(val);
		}
		, setPasswdState: function(){
			var $layer = this.$getLayer();
			
			if(this.getValue() == "N") $layer.find("input:password").attr("disabled", "").attr("disabled", false);
			else $layer.find("input:password").attr("disabled", "disabled");
		}
		, $getRadios: function(){
			return this.$getLayer().find("input:radio");
		}
	}
	
	// 라운드정보
	function clsRoundInfo()
	{
		this._HTMLDom = null;
		this._listData = null;
		
		this._init();
	}
	
	clsRoundInfo.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(2)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:radio").attr("name", "rdoRoundInfo");
			
			this._listData = ["M", "D"];
		}
		, $getLayer: clsProgressStatus.prototype.$getLayer
		, getValue: clsProgressStatus.prototype.getValue
		, $getRadios: function(){
			return this.$getLayer().find("input:radio");
		}
		, setValue: clsProgressStatus.prototype.setValue
	}
	
	// 참여여부
	function clsJoinYN()
	{
		this._HTMLDom = null;
		this._listData = null;
		this._ERRMSG = {
			"_NOVALUE": "참여여부를 선택해 주십시요."
		}
		this.errMsg = null;
		
		this._init();
	}
	
	clsJoinYN.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(4)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:radio").attr("name", "rdoJoinYN");
			
			this._listData = ["Y", "N"];
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, getError: clsProgressStatus.prototype.getError
		, valid: clsProgressStatus.prototype.valid
		, focus: clsProgressStatus.prototype.focus
		, getValue: clsProgressStatus.prototype.getValue
		, setValue: clsProgressStatus.prototype.setValue
	}
	
	// 나의 예약정보
	function clsMyReserveList()
	{
		this._HTMLDom = null;
		this.listData = null;
		this._ERRMSG = {
			"_NOVALUE": "나의 예약정보를 선택해 주십시요."
		}
		this.errMsg = null;
		this.loaded = null;
		this.keyName = null;
		
		this._init();
	}
	
	clsMyReserveList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(3)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.keyName = "예약코드";
			
			this.setList([
				{
					 "예약코드": ""
					, "내용": " ----- 나의 예약정보 선택 ----- "
				}
			]);
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setList: function(thisData){
			if(!this.listData) this.listData = [];
			this.listData = this.listData.concat(thisData);
			this.display();
		}
		, display: function(){
			var $layer = this.$getLayer();
			var thisClass = this;
			
			$layer.find("select").empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("select").append("<option />");
			}
			$layer.find("option").each(function(n){
				$(this).text(thisClass.listData[n]["내용"]);
			});
		}
		, getError: clsProgressStatus.prototype.getError
		, valid: function(){
			var $layer = this.$getLayer();
			var key = this.getKey();
			
			if(!key){
				this.errMsg = "_NOVALUE";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this.$getLayer().find("select").trigger("focus");
		}
		, getKey: function(){
			var n = this.$getLayer().find("option").index(this._HTMLDom["$layer"].find("option:selected"));
			
			return this.listData[n][this.keyName];
		}
		, hide: function(){
			this.$getLayer().hide();
		}
		, show: function(){
			this.$getLayer().show();
		}
		, setKey: function(key){
			for(var i=0;i<this.listData.length;i++){
				if(this.listData[i][this.keyName]+"" == key+"") break;
			}
			
			if(i<this.listData.length){
				this.$getLayer().find("option:eq(" + i + ")").attr("selected", "selected");
			}
		}
		, setLoaded: function(){
			this.loaded = true;
		}
		, getLoaded: function(){
			return this.loaded;
		}
	}
	
	// 초대인원
	function clsInviteCount()
	{
		this._HTMLDom = null;
		this.listData = null;
		this._ERRMSG = {
			"CHECKLIMIT": "초대인원수가 참여자 수보다 적습니다. 참여자 설정 수정 후 다시 시도하여 주세요."
		}
		this.errMsg = null;
		
		this.keyName = null;
		this.limitCount = null;
		
		this._init();
	}
	
	clsInviteCount.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(5)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.limitCount = 0;
			
			this.keyName = "키";
			
			this.listData = [];
			for(var i=1;i<7;i++){
				this.listData.push({
					"키": i
					, "내용": i
				});
			}
			this._display();
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, _display: clsMyReserveList.prototype.display
		, getKey: clsMyReserveList.prototype.getKey
		, setKey: clsMyReserveList.prototype.setKey
		, getError: clsProgressStatus.prototype.getError
		, valid: function(){
			if(this.getKey() < this.limitCount){
				this.errMsg = "CHECKLIMIT"
				return false;
			}
			
			return true;
		}
		, focus: clsMyReserveList.prototype.focus
		, setLimitCount: function(val){
			this.limitCount = val;
		}
	}
	
	// 성별
	function clsGenderList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this.keyName = null;
		
		this._init();
	}
	
	clsGenderList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(6) td p:eq(0)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.keyName = "키";
			
			this.listData = [
				{
					"키": ""
					, "내용": "무관"
				}
				, {
					"키": "M"
					, "내용": "남"
				}
				, {
					"키": "F"
					, "내용": "여"
				}
			];
			this._display();
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, _display:clsMyReserveList.prototype.display
		, getKey: clsMyReserveList.prototype.getKey
		, setKey: clsMyReserveList.prototype.setKey
		, focus: clsMyReserveList.prototype.focus
	}
	
	// 연령대
	function clsAgeList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this.keyName = null;
		
		this.loaded = null;
		
		this._init();
	}
	
	clsAgeList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(6) td p:eq(1)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.keyName = "나이코드";
			
			this.setList([
				{
					"나이코드": ""
					, "내용": "무관"
				}
			]);
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, setList: clsMyReserveList.prototype.setList
		, display: clsMyReserveList.prototype.display
		, getKey: clsMyReserveList.prototype.getKey
		, setKey: clsMyReserveList.prototype.setKey
		, focus: clsMyReserveList.prototype.focus
		, setLoaded: clsMyReserveList.prototype.setLoaded
		, getLoaded: clsMyReserveList.prototype.getLoaded
	}
	
	// 평균타수
	function clsAvgList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this.loaded = null;
		this.keyName = null;
		
		this._init();
	}
	
	clsAvgList.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(7) td p:eq(0)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.keyName = "평균타수코드";
			
			this.setList([
				{
					"평균타수코드": ""
					, "내용": "무관"
				}
			]);
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, setList: clsMyReserveList.prototype.setList
		, display: clsMyReserveList.prototype.display
		, getKey: clsMyReserveList.prototype.getKey
		, setKey: clsMyReserveList.prototype.setKey
		, focus: clsMyReserveList.prototype.focus
		, setLoaded: clsMyReserveList.prototype.setLoaded
		, getLoaded: clsMyReserveList.prototype.getLoaded
	}
	
	// 흡연여부
	function clsSmokeYN()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this.keyName = null;
		
		this._init();
	}
	
	clsSmokeYN.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(7) td p:eq(1)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			this.keyName = "키";
			
			this.listData = [
				{
					"키": ""
					, "내용": "무관"
				}
				, {
					"키": "Y"
					, "내용": "흡연"
				}
				, {
					"키": "N"
					, "내용": "비흡연"
				}
			];
			this._display();
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, _display: clsMyReserveList.prototype.display
		, focus: clsMyReserveList.prototype.focus
		, getKey: clsMyReserveList.prototype.getKey
		, setKey: clsMyReserveList.prototype.setKey
	}
	
	// 상세내용
	function clsNote()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "상세내용을 입력해 주십시요."
		}
		this.errMsg = null;
		
		this._init();
	}
	
	clsNote.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(8)");
			
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, $getLayer: clsProgressStatus.prototype.$getLayer
		, getError: clsProgressStatus.prototype.getError
		, valid: function(){
			var $layer = this._HTMLDom["$layer"];
			
			if(!$layer.find("textarea").val()){
				this.errMsg = "_NOVALUE";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this._HTMLDom["$layer"].find("textarea").trigger("focus");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("textarea").val();
		}
		, setValue: function(val){
			this._HTMLDom["$layer"].find("textarea").val(val);
		}
	}
	
	// 예약자명
	function clsReserverName()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "예약자명을 입력해 주십시요."
		}
		this.errMsg = null;
		
		this._init();
	}
	
	clsReserverName.prototype = {
		_init: function(){
			var $layer = $("div#container section#main_content tr:eq(9)");
			
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, $getLayer: clsProgressStatus.prototype.$getLayer
		, getError: clsProgressStatus.prototype.getError
		, valid: function(){
			var $layer = this._HTMLDom["$layer"];
			
			if(!$layer.find("input:text").val()){
				this.errMsg = "_NOVALUE";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this._HTMLDom["$layer"].find("input:text").trigger("focus");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("input:text").val();
		}
		, setValue: function(val){
			this._HTMLDom["$layer"].find("input:text").val(val);
		}
	}
	
	function clsNewElement()
	{
		this._HTMLDom = null;
	}
	
	clsNewElement.prototype = {
		init: function($thisLayer, $nextLayer){
			$nextLayer.before($thisLayer);
			
			this._HTMLDom = {
				"$layer": $thisLayer
			}
		}
	}
	
	// 지역리스트
	function clsAreaList()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._ERRMSG = {
			"_NOVALUE": "지역을 선택해 주십시요."
		}
		this.errMsg = null;
		this.keyName = null;
		
		this.loaded = null;
	}
	
	clsAreaList.prototype = {
		init: function($thisLayer, $nextLayer){
			clsNewElement.prototype.init.apply(this, arguments);
			
			this.keyName = "지역코드";
			
			this.setList([{
				"지역코드": ""
				, "내용": " 지역선택 "
			}]);
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, setList: clsMyReserveList.prototype.setList
		, display: clsMyReserveList.prototype.display
		, getError: clsProgressStatus.prototype.getError
		, valid: clsMyReserveList.prototype.valid
		, focus: clsMyReserveList.prototype.focus
		, getKey: clsMyReserveList.prototype.getKey
		, setKey: clsMyReserveList.prototype.setKey
		, hide:clsMyReserveList.prototype.hide
		, show: clsMyReserveList.prototype.show
		, setLoaded: clsMyReserveList.prototype.setLoaded
		, getLoaded: clsMyReserveList.prototype.getLoaded
	}
	
	
	// 골프장 코스
	function clsGolfCourse()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "골프장 코스를 입력해 주십시요."
		}
		this.errMsg = null;
	}
	
	clsGolfCourse.prototype = {
		init: function($thisLayer, $nextLayer){
			clsNewElement.prototype.init.apply(this, arguments);
			
			var $layer = this._HTMLDom["$layer"];
			$layer.find("input:text").attr({
				"maxlength": 20
			}).val("");
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, getError: clsProgressStatus.prototype.getError
		, valid: function(){
			var $layer = this.$getLayer();
			
			if(!$layer.find("input:text").val()){
				this.errMsg = "_NOVALUE";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this.$getLayer().find("input:text").trigger("focus");
		}
		, getValue: function(){
			return this.$getLayer().find("input:text").val();
		}
		, setValue: function(val){
			this.$getLayer().find("input:text").val(val);
		}
		, hide: clsMyReserveList.prototype.hide
		, show:clsMyReserveList.prototype.show
	}
	
	// 홀정보
	function clsHoleInfo()
	{
		this._HTMLDom = null;
	}
	
	clsHoleInfo.prototype = {
		init: function($thisLayer, $nextLayer){
			clsNewElement.prototype.init.apply(this, arguments);
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, focus: clsGolfCourse.prototype.focus
		, getValue: clsGolfCourse.prototype.getValue
		, setValue: clsGolfCourse.prototype.setValue
		, hide: clsMyReserveList.prototype.hide
		, show: clsMyReserveList.prototype.show
	}
	
	// 부킹일자
	function clsBookingDate()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "부킹일자를 선택해 주십시요."
		}
		this.errMsg = null;
	}
	
	clsBookingDate.prototype = {
		init: function($thisLayer, $nextLayer){
			clsNewElement.prototype.init.apply(this, arguments);
			
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find("img[alt='달력']").remove();
			
			$layer.find("input:text").attr({
				"readonly": "readonly"
				, "id": "idBookingDate"
			}).datepicker({
				showOn: "both"
				, buttonImage: _ROOT + "/images/btn/icon_calendar.gif"
				, buttonImageOnly: true
				, minDate: new Date()
			});
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, getError: clsProgressStatus.prototype.getError
		, valid: clsGolfCourse.prototype.valid
		, getValue: clsGolfCourse.prototype.getValue
		, setValue: clsGolfCourse.prototype.setValue
		, hide: clsMyReserveList.prototype.hide
		, show: clsMyReserveList.prototype.show
		, focus: function(){
			this.$getLayer().find("input:text").trigger("focus");
		}
		, $getBtnIcon: function(){
			return this.$getLayer().find("img[alt='달력']");
		}
	}
	
	
	// 부킹시간
	function clsBookingTime()
	{
		this._HTMLDom = null;
		this.hourList = null;
		this.minuteList = null;
	}
	
	clsBookingTime.prototype = {
		init: function($thisLayer, $nextLayer){
			clsNewElement.prototype.init.apply(this, arguments);
			
			this.hourList = [];
			this.minuteList = [];
			
			for(var i=0;i<24;i++){
				this.hourList.push({
					"키": ("0"+i).substrEx(-2)
					, "내용": ("0"+i).substrEx(-2)
				});
			}
			
			for(var i=0;i<60;i++){
				this.minuteList.push({
					"키": ("0"+i).substrEx(-2)
					, "내용": ("0"+i).substrEx(-2)
				});
			}
			
			this._display();
		}
		, $getLayer: clsMyReserveList.prototype.$getLayer
		, _display: function(){
			var $layer = this.$getLayer();
			var thisClass = this;
			
			$layer.find("select").empty();
			
			for(var i=0;i<this.hourList.length;i++){
				$layer.find("select:eq(0)").append("<option />");
			}
			
			for(var i=0;i<this.minuteList.length;i++){
				$layer.find("select:eq(1)").append("<option />");
			}
			
			$layer.find("select:eq(0) option").each(function(n){
				$(this).text(thisClass.hourList[n]["내용"]);
			});
			
			$layer.find("select:eq(1) option").each(function(n){
				$(this).text(thisClass.minuteList[n]["내용"]);
			});
		}
		, getValue: function(){
			var $layer = this.$getLayer();
			
			var nHour = $layer.find("select:eq(0) option").index($layer.find("select:eq(0) option:selected"));
			var nMinute = $layer.find("select:eq(1) option").index($layer.find("select:eq(1) option:selected"));
			
			return this.hourList[nHour]["키"] + this.minuteList[nMinute]["키"];
		}
		, setValue: function(val){
			var $layer = this.$getLayer();
			
			if(!val) return;
			
			var arr = val.split(":");
			
			if(arr.length != 2) return;
			
			for(var i=0;i<this.hourList.length;i++){
				if(this.hourList[i]["키"] == arr[0]) break;
			}
			
			if(i<this.hourList.length){
				$layer.find("select:eq(0) option:eq(" + i + ")").attr("selected", "selected");
			}
			
			for(var i=0;i<this.minuteList.length;i++){
				if(this.minuteList[i]["키"] == arr[1]) break;
			}
			
			if(i<this.minuteList.length){
				$layer.find("select:eq(1) option:eq(" + i + ")").attr("selected", "selected");
			}
		}
		, hide: clsMyReserveList.prototype.hide
		, show: clsMyReserveList.prototype.show
	}
	
	// 통신부
	function clsComm()
	{
		// 나의 예약정보
		this.myReserveList = null;
		// 연령대 리스트
		this.ageList = null;
		// 평균타수
		this.avgList = null;
		// 지역
		this.areaList = null;
		
		// 조인룸정보
		this.joinroomInfo = null;
		
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){

		}
		, getMyReserveList: function(){
			var thisClass = this;
			
			this.myReserveList = [];
			
			//ajax
			var serviceName = "getMyReservInfo";
			var options = {
				
			}
			_gf.ajax({
				"sid": "JR001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
				}
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					if(!items.length) items = new Array(items);
					for(var i=0;i<items.length;i++){
						var obj = items[i];
						var reserveDate = _util.nvl(obj["reserveDate"])+"";
						
						thisClass.myReserveList.push({
							"예약코드": _util.nvl(obj["reserveSeq"])
							, "골프장코드": _util.nvl(obj["golfClubId"])
							, "코스명": _util.nvl(obj["golfClubInfo"])
							, "홀": _util.nvl(obj["holeInfo"])
							, "예약날자": _util.nvl(obj["reserveDate"])
							, "예약요일": _util.nvl(obj["bookingDay"])
							, "부킹시간": _util.nvl(obj["bookingTime"])
							//, "내용": _util.nvl(obj["golfClubInfo"]) + "/" + _util.nvl(obj["holeInfo"]) + "/" + reserveDate.substrEx(0, 4) + "-" + reserveDate.substrEx(4, 2) + "-" + reserveDate.substrEx(6, 2) + "(" + _util.nvl(obj["bookingDay"]) + ")/" + _util.nvl(obj["bookingTime"])
							, "내용": _util.nvl(obj["golfClubInfo"]) + "/" + _util.nvl(obj["holeInfo"]) + "/" + _util.nvl(obj["reserveDate"]) + "(" + _util.nvl(obj["bookingDay"]) + ")/" + _util.nvl(obj["bookingTime"])
						});
					}
				}
				
				document.objControl.finishMyReserveList(res);
			});
		}
		, getMyReserveData: function(){
			return this.myReserveList;
		}
		, getAgeList: function(){
			var thisClass = this;
			
			//ajax
			document.objGlobal.getAgeCodeList({
				"콜백": function(ret, listData, args){
					thisClass.ageList = listData;
					document.objControl.finishAgeList(ret);
				}
				, "동기화": true
			});
		}
		, getAgeData: function(){
			return this.ageList;
		}
		, getAvgList: function(){
			var thisClass = this;
			
			//ajax
			document.objGlobal.getAvgCodeList({
				"콜백": function(ret, listData, args){
					thisClass.avgList = listData;
					document.objControl.finishAvgList(ret);
				}
				, "동기화": true
			});
		}
		, getAvgData: function(){
			return this.avgList;
		}
		, getAreaList: function(){
			var thisClass = this;
			
			//ajax
			_gf.getAreaCodeList({
				"콜백": function(ret, listData, args){
					thisClass.areaList = listData;
					document.objControl.finishAreaList(ret);
				}
				, "동기화": true
			});
		}
		, getAreaData: function(){
			return this.areaList;
		}
		, joinroomSubmit: function(arg){
			var thisClass = this;

			//ajax
			if(arg["조인룸키"]) var serviceName = "updateJoinRoom";
			else var serviceName = "registJoinRoom";
			document.objGlobal.ajax({
				"sid":"JR001",
				"servicename":serviceName
			}, {
				"joinRoomSeq": arg["조인룸키"]
				, "procStatus": arg["진행상황"]
				, "openYn": arg["공개여부"]
				, "password": arg["비밀번호"]
				, "roundingInfo": arg["라운드정보"]
				, "joinYn": arg["참여여부"]
				, "reserveSeq": arg["예약키"]
				, "location": arg["지역"]
				, "golfClubInfo": arg["골프장코스"]
				, "holeInfo": arg["홀정보"]
				, "reserveDate": arg["부킹일자"].replace(/-/g, "")
				, "bookingTime": arg["부킹시간"] + "00"
				, "invitCnt": arg["초대인원"]
				, "sex": arg["성별"]
				, "age": arg["연령대"]
				, "aVerage": arg["평균타수"]
				, "smokeYn": arg["흡연여부"]
				, "ment": encodeURIComponent(arg["상세내용"])
				, "rUserName": arg["예약자명"]
			}, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": document.objGlobal.getResultMsg(ret)
				}
				
				document.objControl.finishJoinroomSubmit(res);
			});
		}
		// 조인룸 정보
		, getJoinroomInfo: function(arg){
			var thisClass = this;
			
//			arg = {
//				"조인룸키": null
//			}
			
			this.joinroomInfo = {};
			
			//ajax
			var serviceName = "getDetailJoinRoom";
			document.objGlobal.ajax({
				"sid":"JR001",
				"servicename":serviceName,
				"listcount":1,
				"currpageno":1
			}, {
				"joinRoomSeq": arg["조인룸키"]
			}, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": document.objGlobal.getResultMsg(ret)
				}
				
				if(res["결과코드"] == "00000"){
					var obj = ret["msp"]["contents"]["items"]
					var aGolfInfo = obj["golfClubInfo"].split("/");
					
					var myState = "미신청";
					switch(obj["joinStatus"]){
						case "S":
							myState = "부킹장";
							break;
						case "A":
							myState = "신청완료";
							break;
						case "P":
							myState = "참여완료";
							break;
					}
					
					var szStat = "";
					switch(obj["procStatus"].trim()){
						case "C":
							szStat = "진행중";
							break;
						case "D":
							szStat = "마감";
							break;
						case "E":
							szStat = "완료";
							break;
					}
					
					var objGender = {
						"남": "M"
						, "여": "F"
					}
					
					thisClass.joinroomInfo = {
						"부킹일자": obj["reserveDate"].replace(/\./g, "-")
						, "부킹시간": obj["bookingTime"]
						, "작성자": obj["bookUserId"]
						, "골프장코스": obj["golfClubInfo"]
						, "골프장명": aGolfInfo[0]
						, "코스명": aGolfInfo[1]
						, "홀명": obj["holeInfo"]
						, "공개여부": obj["openYn"]
						, "인사말": obj["ment"]
						, "내상태": myState
						, "신청자수": _util.nvl(obj["applycnt"], 0)
						, "참여자수": _util.nvl(obj["particnt"], 0)
						, "본인참여": obj["joinYn"].trim()
						, "참여조건": {
							"성별": objGender[obj["sex"]]
							, "연령대": obj["ageCd"]
							, "평균타수": obj["avgCd"]
							, "흡연": obj["smokeYn"]
						}
						, "진행상황코드": obj["procStatus"].trim()
						, "진행상황": szStat
						, "초대인원": obj["invitCnt"]
						, "라운드정보": obj["roundingInfo"].trim()
						, "예약키": obj["reserveKey"]
						, "지역코드": obj["location"]
						, "비밀번호": obj["password"]
						, "예약자명": obj["rUserName"]
					}
				}
				
				document.objControl.finishJoinroomInfo(res);
			});
		}
		, getJoinroomData: function(){
			return this.joinroomInfo;
		}
	}
	
	function clsControl()
	{
		this.objComm = null;
		this.objProgressStatus = null;
		this.objOpenYN = null;
		this.objRoundInfo = null;
		this.objJoinYN = null;
		this.objMyReserveList = null;
		this.objInviteCount = null;
		this.objGenderList = null;
		this.objAgeList = null;
		this.objAvgList = null;
		this.objSmokeYN = null;
		this.objNote = null;
		this.objReserverName = null;
		this.objAreaList = null;
		this.objGolfCourse = null;
		this.objHoleInfo = null;
		this.objBookingDate = null;
		this.objBookingTime = null;
		
		this.q_my = document.objUtil.getParam("q_my");
		this.joinroomKey = document.objUtil.getParam("q_seq");
		
		this._permitStart = null;
	}
	
	clsControl.prototype = {
		_init: function(){
			this._preload();
			
			this.objComm = new clsComm();
			this.objProgressStatus = new clsProgressStatus();
			this.objOpenYN = new clsOpenYN();
			this.objRoundInfo = new clsRoundInfo();
			this.objJoinYN = new clsJoinYN();
			this.objMyReserveList = new clsMyReserveList();
			this.objInviteCount = new clsInviteCount();
			this.objGenderList = new clsGenderList();
			this.objAgeList = new clsAgeList();
			this.objAvgList = new clsAvgList();
			this.objSmokeYN = new clsSmokeYN();
			this.objNote = new clsNote();
			this.objReserverName = new clsReserverName();
			this.objAreaList = new clsAreaList();
			this.objGolfCourse = new clsGolfCourse();
			this.objHoleInfo = new clsHoleInfo();
			this.objBookingDate = new clsBookingDate();
			this.objBookingTime = new clsBookingTime();

			this._beforeStart();
			this._bind();
		}
		, _preload: function(){
			_gf.spinStart();
		}
		, _beforeStart: function(){
			var thisClass = this;
			this._permitStart = {
				"나의예약리스트": false
				, "연령대": false
				, "평균타수": false
				, "지역": false
			}
			
			$.ajax({
				url: "join_room_creat02.html"
				, type: "get"
				, dataType: "html"
				, async: false
				, success: function(ret){
					ret = ret.replace(/[\r\n\t]*/g, "");
					
					var s = ret.indexOf("<table");
					var e = ret.indexOf("</table");
					
					var table = ret.substring(s, e) + "</table>";
					
					var tmp = document.createElement("DIV");
					$(tmp).append(table);
					
					thisClass.objAreaList.init($(tmp).find("tr:eq(4)"), thisClass.objJoinYN.$getLayer());
					thisClass.objGolfCourse.init($(tmp).find("tr:eq(4)"), thisClass.objJoinYN.$getLayer());
					thisClass.objHoleInfo.init($(tmp).find("tr:eq(4)"), thisClass.objJoinYN.$getLayer());
					thisClass.objBookingDate.init($(tmp).find("tr:eq(4)"), thisClass.objJoinYN.$getLayer());
					thisClass.objBookingTime.init($(tmp).find("tr:eq(4)"), thisClass.objJoinYN.$getLayer());
					
					$(tmp).remove();
				}
				, error: function(){
					alert("error");
				}
			});
			
			// 나의 예약 리스트
			this.objComm.getMyReserveList();
			
			// 연령대 리스트
			this.objComm.getAgeList();
			
			// 평균타수
			this.objComm.getAvgList();
			// 지역
			this.objComm.getAreaList();
			
			_util.executeThread(function(){
				for(key in thisClass._permitStart){
					if(!thisClass._permitStart[key]) return false;
				}
				
				return true;
			}, function(){
				_gf.spinEnd();
				thisClass._start();
			});
		}
		, _bind: function(){
			var thisClass = this;
			
			// 라운드 정보
			this.objRoundInfo.$getRadios().click(function(){
				setTimeout(function(){
					thisClass.setJoinroomType();
				}, 100);
			});
			
			// 달력아이콘
			/*this.objBookingDate.$getBtnIcon().click(function(){
				thisClass.objBookingDate.focus();
			});*/
			
			// 초대인원 체크
			this.objInviteCount.$getLayer().on("change", "select", function(){
				if(!thisClass.objInviteCount.valid()){
					alert(thisClass.objInviteCount.getError());
				}
			});
			
			// 등록
			$("div#container section#main_content img[alt='등록']").click(function(){
				var progressStatusValue = thisClass.objProgressStatus.getValue();
				var openYN = thisClass.objOpenYN.getValue();
				var passwd = thisClass.objOpenYN.getPasswordValue();
				var roundInfoValue = thisClass.objRoundInfo.getValue();
				var joinYN = thisClass.objJoinYN.getValue();
				var inviteCountKey = thisClass.objInviteCount.getKey();
				var genderKey = thisClass.objGenderList.getKey();
				var ageKey = thisClass.objAgeList.getKey();
				var avgKey = thisClass.objAvgList.getKey();
				var smokeYN = thisClass.objSmokeYN.getKey();
				var noteValue = thisClass.objNote.getValue();
				var reserverName = thisClass.objReserverName.getValue();
				
				var myReserveKey = "";
				var areaKey = "";
				var golfCourseValue = "";
				var holeValue = "";
				var bookingDateValue = "";
				var bookingTimeValue = "";
				
				if(roundInfoValue == "M"){
					myReserveKey = thisClass.objMyReserveList.getKey();
				}else if(roundInfoValue == "D"){
					areaKey = thisClass.objAreaList.getKey();
					golfCourseValue = thisClass.objGolfCourse.getValue();
					holeValue = thisClass.objHoleInfo.getValue();
					bookingDateValue = thisClass.objBookingDate.getValue();
					bookingTimeValue = thisClass.objBookingTime.getValue();
				}
				
				if(!thisClass.objProgressStatus.valid()){
					alert(thisClass.objProgressStatus.getError());
					thisClass.objProgressStatus.focus();
					return;
				}else if(!thisClass.objOpenYN.valid()){
					alert(thisClass.objOpenYN.getError());
					thisClass.objOpenYN.focus();
					return;
				}
				
				if(roundInfoValue == "M"){
					if(!thisClass.objMyReserveList.valid()){
						alert(thisClass.objMyReserveList.getError());
						thisClass.objMyReserveList.focus();
						return;
					}
				}else if(roundInfoValue == "D"){
					if(!thisClass.objAreaList.valid()){
						alert(thisClass.objAreaList.getError());
						thisClass.objAreaList.focus();
						return;
					}else if(!thisClass.objGolfCourse.valid()){
						alert(thisClass.objGolfCourse.getError());
						thisClass.objGolfCourse.focus();
						return;
					}else if(!thisClass.objBookingDate.valid()){
						alert(thisClass.objBookingDate.getError());
						thisClass.objBookingDate.focus();
						return;
					}
				}
				
				if(!thisClass.objJoinYN.valid()){
					alert(thisClass.objJoinYN.getError());
					thisClass.objJoinYN.focus();
					return;
				}if(!thisClass.objInviteCount.valid()){
					alert(thisClass.objInviteCount.getError());
					thisClass.objInviteCount.focus();
					return;
				}else if(!thisClass.objNote.valid()){
					alert(thisClass.objNote.getError());
					thisClass.objNote.focus();
					return;
				}else if(!thisClass.objReserverName.valid()){
					alert(thisClass.objReserverName.getError());
					thisClass.objReserverName.focus();
					return;
				}
				
				_gf.spinStart("sending...");
				thisClass.objComm.joinroomSubmit({
					"조인룸키": thisClass.joinroomKey
					, "진행상황": progressStatusValue
					, "공개여부": openYN
					, "비밀번호": passwd
					, "라운드정보": roundInfoValue
					, "참여여부": joinYN
					, "예약키": myReserveKey
					, "지역": areaKey
					, "골프장코스": golfCourseValue
					, "홀정보": holeValue
					, "부킹일자": bookingDateValue
					, "부킹시간": bookingTimeValue
					, "초대인원": inviteCountKey
					, "성별": genderKey
					, "연령대": ageKey
					, "평균타수": avgKey
					, "흡연여부": smokeYN
					, "상세내용": noteValue
					, "예약자명": reserverName
				});
			});
			
			// 공개여부
			this.objOpenYN.$getRadios().click(function(){
				thisClass.objOpenYN.setPasswdState();
			});
			
			// 취소
			$("div#container section#main_content").on("click", " img[alt='취소']", function(){
				history.back();
			});
		}
		, _start: function(){
			if(this.joinroomKey){
				//document.objGlobal.spinStart("Receiving...");
				this.objComm.getJoinroomInfo({
					"조인룸키": this.joinroomKey
				});
			}else{
				this.objRoundInfo.setValue("M");
			}
		}
		, setJoinroomType: function(){
			var roundValue = this.objRoundInfo.getValue();
			
			if(roundValue == "D"){
				this.objMyReserveList.hide();
				this.objAreaList.show();
				this.objGolfCourse.show();
				this.objHoleInfo.show();
				this.objBookingDate.show();
				this.objBookingTime.show();
			}else{
				this.objMyReserveList.show();
				this.objAreaList.hide();
				this.objGolfCourse.hide();
				this.objHoleInfo.hide();
				this.objBookingDate.hide();
				this.objBookingTime.hide();
			}
		}
		// 나의 예약리스트
		, finishMyReserveList: function(ret){
			var listData = this.objComm.getMyReserveData();
			
			this.objMyReserveList.setList(listData);
			
			this._permitStart["나의예약리스트"] = true;
			//this.objMyReserveList.setLoaded();
		}
		// 연령대
		, finishAgeList: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			var thisData = this.objComm.getAgeData();
			
			this.objAgeList.setList(thisData);
			this._permitStart["연령대"] = true;
			//this.objAgeList.setLoaded();
		}
		// 평균타수
		, finishAvgList: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			var thisData = this.objComm.getAvgData();
			
			this.objAvgList.setList(thisData);
			this._permitStart["평균타수"] = true;
			//this.objAvgList.setLoaded();
		}
		// 지역완료
		, finishAreaList: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			var thisData = this.objComm.getAreaData();
			
			this.objAreaList.setList(thisData);
			this._permitStart["지역"] = true;
			//this.objAreaList.setLoaded();
		}
		// 등록완료
		, finishJoinroomSubmit: function(ret){
			document.objGlobal.spinEnd();
			
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			this.goMyJoinroomList();
		}
		// 조인룸 정보
		, finishJoinroomInfo: function(ret){
			var thisClass = this;
			
			_gf.spinEnd();
			
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			var thisData = this.objComm.getJoinroomData();
			
			this.objProgressStatus.setValue(thisData["진행상황코드"]);
			this.objOpenYN.setValue(thisData["공개여부"]);
			if(thisData["공개여부"] == "N") this.objOpenYN.setPasswordValue(thisData["비밀번호"]);
			this.objRoundInfo.setValue(thisData["라운드정보"]);
			this.objJoinYN.setValue(thisData["본인참여"]);
			this.objReserverName.setValue(thisData["예약자명"]);
			this.objInviteCount.setLimitCount(thisData["참여자수"]);
			
			if(thisData["예약키"]){
				this.objMyReserveList.setKey(thisData["예약키"]);
			}else{
				thisClass.objAreaList.setKey(thisData["지역코드"]);
				this.objGolfCourse.setValue(thisData["골프장코스"]);
				this.objHoleInfo.setValue(thisData["홀명"]);
				this.objBookingDate.setValue(thisData["부킹일자"]);
				this.objBookingTime.setValue(thisData["부킹시간"]);
				this.objInviteCount.setKey(thisData["초대인원"]);
				this.objGenderList.setKey(thisData["참여조건"]["성별"]);
				
				thisClass.objAgeList.setKey(thisData["참여조건"]["연령대"]);
				thisClass.objAvgList.setKey(thisData["참여조건"]["평균타수"]);
				
				this.objSmokeYN.setKey(thisData["참여조건"]["흡연"]);
				this.objNote.setValue(thisData["인사말"]);
			}
		}
		// 나의 조인룸 이동
		, goMyJoinroomList: function(){
			var szLink = _ROOT + "/booking/join_room.html?q_my=Y";
			document.location.href = szLink;
		}
	}
	
	document.objControl = new clsControl();
	document.objControl._init();
});
